<%@ page language="java" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
				 com.scalar.chiptrack.commons.Constants,
				 com.scalar.chiptrack.users.Functionality,
				 com.scalar.chiptrack.users.User"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>

<chiptrack:checkLogon sourcePage="/bomSetup.do?action=BomSetup" />

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/kit_making.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>
<SCRIPT language="JavaScript">
window.onload = init;

function init()
{
    if ( document.bomSetupForm['bomSetup.assemblyProcessStepId'] != null )
    {
        qs_1 = new QuickSearch(document.bomSetupForm['bomSetup.assemblyProcessStepId'], document.bomSetupForm.qs1, false);
    }

}
function submitPage(action)
{
    var pa	= document.getElementById("errors");
    var form = document.bomSetupForm;
    pa.innerHTML = '';
    if(action == 'BomSetup')
    {
        form.action = "<%=chipTracContext%>/bomSetup.do?action=BomSetup";
        form.submit();
    }
    if(action == 'OPEN')
    {
            form.action = "<%=chipTracContext%>/bomSetup.do?action=OpenBomPartNumbers";
            form.submit();
    }
    else if( action == 'ADDMORE' )
    {
        form.action = "<%=chipTracContext%>/bomSetup.do?action=addmoreBomPartNumbers";
        form.submit();
    }
    else if( action == 'SAVE' )
    {
        if( validations('SAVE') == true )
		{
            form.action = "<%=chipTracContext%>/bomSetup.do?action=SaveBoardMaking";
            form.submit();
        }
    }
    else if( action == 'DELETE' )
    {
        if (document.bomSetupForm['bomSetup.bomPartNumbersAndQuantitylist[0].bomProcessStepId'].value == "-1"  )
        {
            pa.innerHTML ='<li> Bom part numbers not setup for the part number';
            return;
        }
        form.action = "<%=chipTracContext%>/bomSetup.do?action=delete&bomProcessStepId="+arguments[1];
        form.submit();
    }
}

function validations(action)
{
    var errors		= "";
    var li = document.getElementById( "message" );
    li.style.visibility = "visible";
    errMsg = "";

    if( document.bomSetupForm.rowcount.value != null )
    {
        var length = document.bomSetupForm.rowcount.value;
        if( length > 0 )
        {
            if( action == 'SAVE' )
            {
                var atleastOneBomSelected = false;
                for( var k = 0; k < length; k++ )
                {
                    var quantity  = document.bomSetupForm['bomSetup.bomPartNumbersAndQuantitylist['+k+'].quantity'].value;
                    var bomProcessStepId = document.bomSetupForm['bomSetup.bomPartNumbersAndQuantitylist['+k+'].bomProcessStepId'].value;
                    for( var i = 0; i < k; i++ )
                    {
                        var lastBomProcessStepId = document.bomSetupForm['bomSetup.bomPartNumbersAndQuantitylist['+i+'].bomProcessStepId'].value;
                        lastBomProcessStepId = lastBomProcessStepId.trim();
                        if( ( bomProcessStepId == lastBomProcessStepId )&&( lastBomProcessStepId != '-1') )
                        {
                            errors = errors+"<li> BomPartNumber already selected please select another BomPartNumber";
                            li.innerHTML = errors;
                            document.bomSetupForm['bomSetup.bomPartNumbersAndQuantitylist['+k+'].bomProcessStepId'].focus();
                            return false;
                        }
                    }
                    if( bomProcessStepId != "-1" )
                    {
                        atleastOneBomSelected = true;
                        if( quantity == "" )
                        {
                            errors = errors + "<li>Please enter the Quantity";
                            li.innerHTML = errors;
                            document.bomSetupForm['bomSetup.bomPartNumbersAndQuantitylist['+k+'].quantity'].focus();
                            return false;
                        }
                    }
                    else
                    {
                        if( quantity != "" )
                        {
                            errors = errors + "<li>Please select the Bom Part Number";
                            li.innerHTML = errors;
                            document.bomSetupForm['bomSetup.bomPartNumbersAndQuantitylist['+k+'].bomProcessStepId'].focus();
                            return false;
                        }
                    }
                }
                if( !atleastOneBomSelected )
                {
                    errors = errors + "<li>Please select a Bom Part Number";
                    li.innerHTML = errors;
                    return false;
                }
            }
        }
    }
    return true;
}
function quickSearchPartNo()
{
    if ( window.event.keyCode == 13 )
    {
        submitPage('OPEN');
    }
}
function reset()
{
    document.bomSetupForm.reset();
    qs_1.resetQuickSearchCntrl();

}
</SCRIPT>
</HEAD>
<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->
<html:form name="bomSetupForm" action="/bomSetup" type="com.scalar.chiptrack.operations.process.forms.BomSetupForm" >
<bean:define id="bomSetupForm" name="bomSetupForm" type="com.scalar.chiptrack.operations.process.forms.BomSetupForm"/>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
    <TBODY>
    <TR>
	    <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
    <!-- Side Navigation start -->
    <%@ include file="/jsp/operations/product_menu.jsp" %>
    <!-- end of the side navigations -->
    <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8>
    </TD>
    <TD bgcolor="#ffffff"><IMG height=460 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
    <TD valign="top" width="100%">
    <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
            <TABLE width="90%" align="right" cellpadding="2" cellspacing="3" border="0">
                <tr><td colspan='5' class="NArialW" align=center>BOM Setup</td></tr>
                <nested:nest property="bomSetup">
                <TR>
                    <TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='5'></TD>
                </TR>

                <tr><td colspan='5' align="left" class='NArialL'>&nbsp;<FONT id="errors" color='FF0000'></font></td></tr>
                <TR><TD colspan='5'><chiptrack:errors styleClass="NArialL"/></TD></TR>
                <TR><TD colspan='5'><chiptrack:info styleClass="NArialL"/></TD></TR>
                <% if ( !user.isActionAllowed ( Functionality.BOM_SETUP, User.USER_ACTION_MODIFY  )  ) { %>
                <tr><td colspan='4'>
                <font class='NArialS' color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b>
                </font></td></tr>
                <% } %>
                <tr>
                    <td colspan=5><font class="NArialL"><font align=left color="FF0000" id=message ></font></font></td>
                </tr>
                <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='5'></TD></TR>
                <TR>

                    <TD class='NArialL' width='25%' >Process Type :</TD>
                    <TD class="NArialL" width='30%' >
                        <html:select property="processType" styleClass="txfield"  onchange="javascript:submitPage('BomSetup');" >
                            <html:options collection="processTypes" property="value" labelProperty="label"/>
                        </html:select> &nbsp;&nbsp;
                    </TD>
                    <TD class='NArialL' width='20%'> &nbsp;</TD>
                    <TD class='NArialL' width='20%'> &nbsp;</TD>
                    <TD class='NArialL' width='10%' >&nbsp;</TD>
                </TR>

                <TR>
                    <TD class='NArialL' width='25%' >Quick Search :</TD>
                    <TD class="NArialL" width='30%' >
                        <input type="text" name="qs1" class="txfield" size='30' onkeyup='quickSearch(qs_1);quickSearchPartNo();'/>
                    </TD>
                    <TD class='NArialL' width='20%'> &nbsp;</TD>
                    <TD class='NArialL' width='20%'> &nbsp;</TD>
                    <TD class='NArialL' width='10%' >&nbsp;</TD>
                </TR>
                
                <TR>
                    <TD class='NArialL' width='25%' >Part Number :</TD>
                    <TD class="NArialL" width='30%' >
                        <nested:select property="assemblyProcessStepId" styleClass="txfield"  onchange="javascript:submitPage('OPEN');" >
                            <html:option value="-1">--Select Part Number--</html:option>
                            <html:options collection="partNumberSelectList" property="value" labelProperty="label"/>
                        </nested:select> &nbsp;&nbsp;
                    </TD>
                    <TD class='NArialL' width='20%'> &nbsp;</TD>
                    <TD class='NArialL' width='20%'> &nbsp;</TD>
                    <TD class='NArialL' width='10%' >&nbsp;</TD>
                </TR>
                <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                <logic:equal name="blankBom" value="TRUE">
                <tr >
                    <%--<TD class='NArialL' width='5%' >&nbsp;</TD>--%>
                    <td align="center" width='25%' bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Bom Part Number</font></font></td>
                    <td align="center" width='20%' bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Quantity</font></font></td>
                    <td align="center" width='20%' bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Is Primary Part</font></font></td>
                    <td align="center" width='10%' bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Actions</font></font></td>
                </tr>
                <% int rowcount = 0; %>
                <nested:iterate name="bomSetup" property="bomPartNumbersAndQuantitylist">
                <TR bgcolor='<%=rowcount % 2 == 0 ? "#FFFFEE" : "#DEE1E2"%>'>
                    <%--<TD class='NArialL' width='5%' >&nbsp;</TD>--%>
                    <TD align="center" class='NArialL' width='25%'>
                        <nested:select property="bomProcessStepId" styleClass="txfield">
                            <html:option value="-1">--Select BOM--</html:option>
                            <html:options collection="BomPartNumbers" property="value" labelProperty="label" />
                        </nested:select>
                    </TD>

                    <TD  align="center" class='NArialL' width='20%'>
                        <nested:text property="quantity" styleClass="txfield" maxlength="20" size="16"  onkeypress="javascript:restrictCharacters(this,7,2)"  />
                    </TD>
                    <TD  align="center" class='NArialL' width='20%'>
                        <nested:checkbox property="primaryPartNumber" styleClass="txfield"/>
                    </TD>

                    <TD align="center" width='10%' class='NArialL' >
                        <nested:greaterThan value="0" property="bomProcessStepId">
                        <a href="javascript:submitPage('DELETE','<nested:write property="bomProcessStepId"/>');" onMouseOver="window.status='Click to DeLink Bom part number';return true" onMouseout="window.status='';return ">Delete</a>&nbsp;&nbsp;
                        </nested:greaterThan> &nbsp;
                    </TD>
                </TR>
                <% rowcount++; %>
                </nested:iterate>
                <input type="hidden" name="rowcount" value="<%=rowcount%>">
                <%--<TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>--%>
                <TR><TD colspan="5"><FONT id="font1"></FONT></TD></TR>
                <%--<TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>--%>                
                <TR>
                    <TD colspan='3' align="right">
                        <chiptrack:restrictedLink functionality='<%=Functionality.BOM_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('ADDMORE');" onmouseover="window.status='Click to Add more Bom Part Numbers';return true" onmouseout="window.status='';return true">
                            <img border="0" src="<%=chipTracContext%>/jsp/includes/images/addmore.gif" width="53" height="17" title="Click here to Add more BomPart Numbers">
                        </chiptrack:restrictedLink>
                    </TD>
                    <TD colspan='2' align="right">&nbsp;</td>
                </TR>

                <TR>
                    <TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD>
                </TR>
                <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                
                <TR>

                    <TD colspan='2' align=center>
                        <chiptrack:restrictedLink functionality='<%=Functionality.BOM_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('SAVE');" onmouseover="window.status='Click to save Bom Setup details';return true" onmouseout="window.status='';return true">
                            <img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17" title="Click here to save Bom Setup details">
                        </chiptrack:restrictedLink>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <A HREF="javascript:reset();"><IMG src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border=0 onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></A>
                    </TD>
                    <TD  colspan='3' align=left>&nbsp;&nbsp;
                    </TD>
                </TR>
                </logic:equal>
                </nested:nest>
            </TABLE>
    </html:form>
    </TD>
        <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
    </TR>
    </TABLE>
    <!-- Footer starts here -->
    <%@ include file="/jsp/includes/footer.jsp" %>
    <!-- footer end here -->
    </BODY>
    </HTML>

